package com.dbh.algorithm.future.jdk;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 *  主方法
 *
 * @author dongbanghui
 * @date 2018/06/26
 */
public class FutureMain {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //构造FutureTask
        FutureTask<String> futureTask = new FutureTask<>(new RealData("a"));
        ExecutorService executors = Executors.newFixedThreadPool(1);
        //执行FutureTask，相当上例中的client.request("a") 发送请求
        executors.submit(futureTask);

        System.out.println("请求完毕");

        try {
            //模拟业务逻辑处理
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("数据=" + futureTask.get());

    }
}
